############################
# calculating German ENPP  #
############################


### germany enpp

ger_seat<-read.csv("germany_seatshare.csv")
attach(ger_seat)
ger_seat$perseat=absseat/totseats
ger_seat<-na.omit(ger_seat)


##calculate two types of ENPP

#molinar

tb_enpp_np<-
  ger_seat %>%group_by(edate) %>%
  summarise(enpp_np=1+(1/(sum(perseat^2))*((sum(perseat^2)-max(perseat^2))/sum(perseat^2))))

tb_enpp<-ger_seat %>%group_by(edate) %>%
  summarise(enpp=1/sum(perseat^2))

#combine two tibbles
enpp_germany<-data.frame(tb_enpp_np,tb_enpp)

#output .csv
write.csv(enpp_germany,"enpp_germany.csv")